<template>
	<view class="rank-container">
		<view class="header">
			<view class="header-item">
				<text class="big">成长总积分</text>
				<text class="bigger mark">{{headData.studyPoint}}</text>
			</view>
			<view class="header-item">
				<text>您的段位</text>
				<text class="mark">{{headData.rankLevel}}</text>
			</view>
			<view class="header-item">
				<text>我的排名</text>
				<text class="mark">{{headData.rank}}</text>
			</view>
		</view>
		<view class="main">
			<view class="title">
				<view class="bold">学习标兵</view>
				<view class="level-2">
					<text class="bold">{{mainData.totalCount}}</text>人参与排名
				</view>
			</view>
			<view class="list-item" v-for="(item, index) in mainData.topList" :key="index">
				<view class="user">
					<view 
					class="index" 
					:class="{
						'first':index==0, 
						'second':index==1, 
						'third':index==2
					}">
						{{index + 1}}
					</view>
					<view class="icon">{{iconName(item.userName)}}</view>
					<view>{{item.userName}}</view>
				</view>
				<view class="point mark">{{item.studyPoint}}分</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		name: 'rank',
		data(){
			return{
				headData:{},
				mainData:{}
			}
		},
		computed:{
			iconName:function(){
				return function(e){
					if(!e){
						return;
					}
					if(e.length < 2){
						return e;
					}
					return e.substring(e.length - 2, e.length);
				}
			}
		},
		onLoad() {
			let p1 = this.$http.request({
				url: 'api/School/MyStudyRecord'
			})
			let p2 = this.$http.request({
				url: 'api/School/StudyRecordTopx'
			})
			Promise.all([p1, p2]).then(resp=>{
				this.headData = resp[0];
				this.mainData = resp[1];
			})
		}
	}
</script>

<style lang="scss" scoped>
	.rank-container{
		width: 100vw;
		min-height: 100vh;
		background-color: $uni-color-main-dark;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 20rpx;
		.mark{
			color: $uni-color-main-dark;
			font-weight: bold;
		}
		/* 头部卡片 */
		.header{
			width: 98%;
			background-color: #fff;
			height: 300rpx;
			border-radius: 10rpx;
			box-sizing: border-box;
			padding: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			.header-item{
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 35rpx;
				font-weight: bold;
				.big{
					font-size: 40rpx;
				}
				.bigger{
					font-size: 60rpx;
				}
			}
		}
		/* 内容列表 */
		.main{
			width: 98%;
			background-color: #fff;
			border-radius: 10rpx;
			box-sizing: border-box;
			padding: 20rpx;
			margin-top: 20rpx;
			.title{
				border-bottom: 1rpx solid #eee;
				padding: 10rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				position: relative;
				font-size: 35rpx;
				font-weight: bold;
				.level-2{
					color: #555;
					font-weight: normal;
					.bold{
						font-weight: bold;
						margin-right: 10rpx;
						font-size: 40rpx;
					}
				}
			}
			.title::before{
				content: "";
				width: 8rpx;
				height: 50%;
				background-color: #ff0000;
				position: absolute;
				left: -20rpx;
				top: 25%;
			}
			.list-item{
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 35rpx;
				font-weight: bold;
				padding: 10rpx;
				height: 150rpx;
				box-sizing: border-box;
				.user{
					display: flex;
					justify-content: space-around;
					align-items: center;
					.index{
						font-style: italic;
						&.first{
							color: $uni-color-main-dark;
						}
						&.second{
							color: $uni-color-warning;
						}
						&.third{
							color: #1296db;
						}
					}
					.icon{
						margin: 0 20rpx 0 40rpx;
						width: 90rpx;
						height: 90rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						padding: 10rpx;
						background-color: #1296db;
						color: #fff;
						border-radius: 50%;
						font-weight: normal;
					}
				}
				.point{
					font-size: 40rpx;
				}
			}
		}
	}
</style>
